VERSION 5.00
Begin VB.Form Form1 
   BackColor       =   &H00808080&
   Caption         =   "Digital Volt Meter : delabs"
   ClientHeight    =   6795
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   8730
   FillColor       =   &H00C0FFFF&
   Icon            =   "dvm_main.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   Picture         =   "dvm_main.frx":030A
   ScaleHeight     =   6795
   ScaleWidth      =   8730
   StartUpPosition =   3  'Windows Default
   Begin VB.Timer Timer3 
      Enabled         =   0   'False
      Interval        =   1
      Left            =   5040
      Top             =   6360
   End
   Begin VB.CommandButton Command12 
      Caption         =   "Exit"
      Height          =   255
      Left            =   7920
      TabIndex        =   28
      Top             =   6480
      Width           =   735
   End
   Begin VB.TextBox Text7 
      Alignment       =   2  'Center
      Appearance      =   0  'Flat
      BackColor       =   &H00400000&
      BorderStyle     =   0  'None
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H0000FFFF&
      Height          =   375
      Left            =   360
      TabIndex        =   24
      Text            =   "out"
      Top             =   2640
      Visible         =   0   'False
      Width           =   855
   End
   Begin VB.Timer Timer2 
      Enabled         =   0   'False
      Interval        =   10
      Left            =   4560
      Top             =   6360
   End
   Begin VB.Frame Frame4 
      BackColor       =   &H000040C0&
      Caption         =   "Power"
      ForeColor       =   &H00E0E0E0&
      Height          =   1335
      Left            =   360
      TabIndex        =   22
      Top             =   5280
      Width           =   735
      Begin VB.CommandButton Command9 
         Caption         =   "ON"
         Height          =   495
         Left            =   120
         TabIndex        =   23
         Top             =   720
         Width           =   495
      End
      Begin VB.Shape Shape10 
         BackColor       =   &H000040C0&
         BackStyle       =   1  'Opaque
         BorderStyle     =   0  'Transparent
         BorderWidth     =   2
         Height          =   135
         Left            =   120
         Shape           =   4  'Rounded Rectangle
         Top             =   360
         Width           =   495
      End
   End
   Begin VB.TextBox Text6 
      Alignment       =   2  'Center
      Appearance      =   0  'Flat
      BackColor       =   &H00000000&
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H0000FF00&
      Height          =   375
      Left            =   360
      TabIndex        =   21
      Text            =   "status"
      Top             =   1440
      Visible         =   0   'False
      Width           =   855
   End
   Begin VB.TextBox Text5 
      Alignment       =   2  'Center
      Appearance      =   0  'Flat
      BackColor       =   &H00000000&
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H0000FF00&
      Height          =   375
      Left            =   360
      TabIndex        =   20
      Text            =   "value"
      Top             =   960
      Visible         =   0   'False
      Width           =   855
   End
   Begin VB.TextBox Text4 
      Alignment       =   2  'Center
      Appearance      =   0  'Flat
      BackColor       =   &H00000000&
      BorderStyle     =   0  'None
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H0000FF00&
      Height          =   375
      Left            =   360
      TabIndex        =   19
      Text            =   "digits"
      Top             =   480
      Visible         =   0   'False
      Width           =   855
   End
   Begin VB.Timer Timer1 
      Enabled         =   0   'False
      Interval        =   10
      Left            =   4080
      Top             =   6360
   End
   Begin VB.Frame Frame2 
      BackColor       =   &H00800000&
      Caption         =   "Input"
      ForeColor       =   &H00C0FFFF&
      Height          =   1935
      Left            =   1920
      TabIndex        =   17
      Top             =   120
      Width           =   4935
      Begin VB.TextBox dvm_reading 
         Alignment       =   2  'Center
         Appearance      =   0  'Flat
         BackColor       =   &H00400000&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   45
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H0000FF00&
         Height          =   1185
         Left            =   240
         TabIndex        =   18
         Text            =   "1245"
         Top             =   360
         Width           =   3975
      End
      Begin VB.Shape Shape9 
         BackColor       =   &H00800000&
         BackStyle       =   1  'Opaque
         BorderStyle     =   0  'Transparent
         BorderWidth     =   2
         Height          =   135
         Left            =   4440
         Shape           =   4  'Rounded Rectangle
         Top             =   480
         Width           =   375
      End
   End
   Begin VB.Frame Frame3 
      BackColor       =   &H00400040&
      Caption         =   "Output"
      ForeColor       =   &H00FFFFFF&
      Height          =   1335
      Left            =   1920
      TabIndex        =   9
      Top             =   2160
      Width           =   4935
      Begin VB.CommandButton Command1 
         Caption         =   "Q7"
         Height          =   375
         Left            =   120
         TabIndex        =   25
         Top             =   840
         Width           =   495
      End
      Begin VB.CommandButton Command8 
         Caption         =   "Q0"
         Height          =   375
         Left            =   4320
         TabIndex        =   16
         Top             =   840
         Width           =   495
      End
      Begin VB.CommandButton Command7 
         Caption         =   "Q1"
         Height          =   375
         Left            =   3720
         TabIndex        =   15
         Top             =   840
         Width           =   495
      End
      Begin VB.CommandButton Command6 
         Caption         =   "Q2"
         Height          =   375
         Left            =   3120
         TabIndex        =   14
         Top             =   840
         Width           =   495
      End
      Begin VB.CommandButton Command5 
         Caption         =   "Q3"
         Height          =   375
         Left            =   2520
         TabIndex        =   13
         Top             =   840
         Width           =   495
      End
      Begin VB.CommandButton Command4 
         Caption         =   "Q4"
         Height          =   375
         Left            =   1920
         TabIndex        =   12
         Top             =   840
         Width           =   495
      End
      Begin VB.CommandButton Command3 
         Caption         =   "Q5"
         Height          =   375
         Left            =   1320
         TabIndex        =   11
         Top             =   840
         Width           =   495
      End
      Begin VB.CommandButton Command2 
         Caption         =   "Q6"
         Height          =   375
         Left            =   720
         TabIndex        =   10
         Top             =   840
         Width           =   495
      End
      Begin VB.Shape Shape8 
         BackColor       =   &H00E0E0E0&
         BackStyle       =   1  'Opaque
         BorderStyle     =   0  'Transparent
         BorderWidth     =   2
         Height          =   135
         Left            =   4320
         Shape           =   4  'Rounded Rectangle
         Top             =   360
         Width           =   495
      End
      Begin VB.Shape Shape7 
         BackColor       =   &H00E0E0E0&
         BackStyle       =   1  'Opaque
         BorderStyle     =   0  'Transparent
         BorderWidth     =   2
         Height          =   135
         Left            =   3720
         Shape           =   4  'Rounded Rectangle
         Top             =   360
         Width           =   495
      End
      Begin VB.Shape Shape6 
         BackColor       =   &H00E0E0E0&
         BackStyle       =   1  'Opaque
         BorderStyle     =   0  'Transparent
         BorderWidth     =   2
         Height          =   135
         Left            =   3120
         Shape           =   4  'Rounded Rectangle
         Top             =   360
         Width           =   495
      End
      Begin VB.Shape Shape5 
         BackColor       =   &H00E0E0E0&
         BackStyle       =   1  'Opaque
         BorderStyle     =   0  'Transparent
         BorderWidth     =   2
         Height          =   135
         Left            =   2520
         Shape           =   4  'Rounded Rectangle
         Top             =   360
         Width           =   495
      End
      Begin VB.Shape Shape4 
         BackColor       =   &H00E0E0E0&
         BackStyle       =   1  'Opaque
         BorderStyle     =   0  'Transparent
         BorderWidth     =   2
         Height          =   135
         Left            =   1920
         Shape           =   4  'Rounded Rectangle
         Top             =   360
         Width           =   495
      End
      Begin VB.Shape Shape3 
         BackColor       =   &H00E0E0E0&
         BackStyle       =   1  'Opaque
         BorderStyle     =   0  'Transparent
         BorderWidth     =   2
         Height          =   135
         Left            =   1320
         Shape           =   4  'Rounded Rectangle
         Top             =   360
         Width           =   495
      End
      Begin VB.Shape Shape2 
         BackColor       =   &H00E0E0E0&
         BackStyle       =   1  'Opaque
         BorderStyle     =   0  'Transparent
         BorderWidth     =   2
         Height          =   135
         Left            =   720
         Shape           =   4  'Rounded Rectangle
         Top             =   360
         Width           =   495
      End
      Begin VB.Shape Shape1 
         BackColor       =   &H00E0E0E0&
         BackStyle       =   1  'Opaque
         BorderStyle     =   0  'Transparent
         BorderWidth     =   2
         Height          =   135
         Left            =   120
         Shape           =   4  'Rounded Rectangle
         Top             =   360
         Width           =   495
      End
   End
   Begin VB.Frame Frame1 
      BackColor       =   &H00808000&
      Caption         =   "Port"
      ForeColor       =   &H00C0FFFF&
      Height          =   2535
      Left            =   1680
      TabIndex        =   0
      Top             =   4200
      Visible         =   0   'False
      Width           =   1215
      Begin VB.CommandButton Command11 
         Caption         =   "Close Me"
         Height          =   255
         Left            =   240
         TabIndex        =   27
         Top             =   2160
         Width           =   855
      End
      Begin VB.ComboBox Combo1 
         BackColor       =   &H00C0FFC0&
         Height          =   315
         ItemData        =   "dvm_main.frx":5144
         Left            =   240
         List            =   "dvm_main.frx":5151
         TabIndex        =   8
         Text            =   "port"
         Top             =   480
         Width           =   855
      End
      Begin VB.TextBox Text3 
         Alignment       =   2  'Center
         Appearance      =   0  'Flat
         BackColor       =   &H00C0FFC0&
         ForeColor       =   &H00404000&
         Height          =   285
         Left            =   360
         TabIndex        =   7
         Top             =   1680
         Width           =   735
      End
      Begin VB.TextBox Text2 
         Alignment       =   2  'Center
         Appearance      =   0  'Flat
         BackColor       =   &H00C0FFC0&
         ForeColor       =   &H00404000&
         Height          =   285
         Left            =   360
         TabIndex        =   6
         Top             =   1320
         Width           =   735
      End
      Begin VB.TextBox Text1 
         Alignment       =   2  'Center
         Appearance      =   0  'Flat
         BackColor       =   &H00C0FFC0&
         ForeColor       =   &H00404000&
         Height          =   285
         Left            =   360
         TabIndex        =   2
         Top             =   960
         Width           =   735
      End
      Begin VB.Label Label4 
         Alignment       =   2  'Center
         Appearance      =   0  'Flat
         BackColor       =   &H00C0C0FF&
         BackStyle       =   0  'Transparent
         Caption         =   "Cnt"
         ForeColor       =   &H00C0FFC0&
         Height          =   255
         Left            =   0
         TabIndex        =   5
         Top             =   1680
         Width           =   375
      End
      Begin VB.Label Label3 
         Alignment       =   2  'Center
         Appearance      =   0  'Flat
         BackColor       =   &H00C0C0FF&
         BackStyle       =   0  'Transparent
         Caption         =   "Inp"
         ForeColor       =   &H00C0FFC0&
         Height          =   255
         Left            =   0
         TabIndex        =   4
         Top             =   1320
         Width           =   375
      End
      Begin VB.Label Label2 
         Alignment       =   2  'Center
         Appearance      =   0  'Flat
         BackColor       =   &H00FFC0C0&
         BackStyle       =   0  'Transparent
         Caption         =   "Out"
         ForeColor       =   &H00C0FFC0&
         Height          =   255
         Left            =   0
         TabIndex        =   3
         Top             =   960
         Width           =   375
      End
      Begin VB.Label Label1 
         Alignment       =   2  'Center
         BackColor       =   &H00C0FFC0&
         BackStyle       =   0  'Transparent
         Caption         =   "Select Port"
         ForeColor       =   &H00C0FFC0&
         Height          =   255
         Left            =   120
         TabIndex        =   1
         Top             =   240
         Width           =   1095
      End
   End
   Begin VB.CommandButton Command10 
      Caption         =   "Set Port"
      Height          =   255
      Left            =   360
      TabIndex        =   26
      Top             =   4440
      Width           =   735
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'Printer         Data Port        Status          Control
'LPT1            0x03bc          0x03bd          0x03be
'LPT2            0x0378          0x0379          0x037a
'LPT3            0x0278          0x0279          0x027a
Dim output_port As Integer
Dim input_port As Integer
Dim control_port As Integer
Dim read_digits As Integer
Dim read_value As Integer
Dim read_status As Integer
Dim outport_value As Integer
Dim latch_out1 As Integer
Dim out7_flag, out6_flag, out5_flag, out4_flag, out3_flag, out2_flag, out1_flag, out0_flag
Dim pwr_flag
Dim edge_detect
Dim digit_1, digit_2, digit_3, digit_4, digit_5, plus_minus
Dim d1_dun, d2_dun, d3_dun, d4_dun, d5_dun
Private Sub Combo1_Click()
output_port = Combo1.Text
input_port = output_port + 1
control_port = output_port + 2
Text1.Text = "0x" & Hex(output_port)
Text2.Text = "0x" & Hex(input_port)
Text3.Text = "0x" & Hex(control_port)
End Sub

Private Sub Command1_Click()
If out7_flag = 0 And pwr_flag = 1 Then
Shape1.BackColor = &H80FF&
outport_value = outport_value Or &H80 '10000000 8th bit on
Text7 = Hex(outport_value)
out7_flag = 1
Else
Shape1.BackColor = &HE0E0E0
outport_value = outport_value And &H7F '01111111 8th bit off
Text7 = Hex(outport_value)
out7_flag = 0
End If
End Sub

Private Sub Command10_Click()
Frame1.Visible = True
End Sub

Private Sub Command11_Click()
Frame1.Visible = False
End Sub

Private Sub Command12_Click()
Command9_Click
Beep
End
End Sub

Private Sub Command2_Click()
If out6_flag = 0 And pwr_flag = 1 Then
Shape2.BackColor = &H80FF&
outport_value = outport_value Or &H40 '01000000 7th bit on
Text7 = Hex(outport_value)
out6_flag = 1
Else
Shape2.BackColor = &HE0E0E0
outport_value = outport_value And &HBF '10111111 7th bit off
Text7 = Hex(outport_value)
out6_flag = 0
End If
End Sub

Private Sub Command3_Click()
If out5_flag = 0 And pwr_flag = 1 Then
Shape3.BackColor = &H80FF&
outport_value = outport_value Or &H20 '00100000 6th bit on
Text7 = Hex(outport_value) ' this is a monitor make it invisible later
out5_flag = 1
Else
Shape3.BackColor = &HE0E0E0
outport_value = outport_value And &HDF '11011111 6th bit off
Text7 = Hex(outport_value) ' this is a put to monitor or say debug
out5_flag = 0
End If
End Sub

Private Sub Command4_Click()
If out4_flag = 0 And pwr_flag = 1 Then
Shape4.BackColor = &H80FF&
outport_value = outport_value Or &H10 '00010000 5th bit on
Text7 = Hex(outport_value)
out4_flag = 1
Else
Shape4.BackColor = &HE0E0E0
outport_value = outport_value And &HEF '11101111 5th bit off
Text7 = Hex(outport_value)
out4_flag = 0
End If
End Sub

Private Sub Command5_Click()
If out3_flag = 0 And pwr_flag = 1 Then
Shape5.BackColor = &H80FF&
outport_value = outport_value Or &H8  '00001000 4th bit on
Text7 = Hex(outport_value)
out3_flag = 1
Else
Shape5.BackColor = &HE0E0E0
outport_value = outport_value And &HF7 '11110111 4th bit off
Text7 = Hex(outport_value)
out3_flag = 0
End If
End Sub

Private Sub Command6_Click()
If out2_flag = 0 And pwr_flag = 1 Then
Shape6.BackColor = &H80FF&
outport_value = outport_value Or &H4  '00000100 3rd bit on
Text7 = Hex(outport_value)
out2_flag = 1
Else
Shape6.BackColor = &HE0E0E0
outport_value = outport_value And &HFB '11111011 3rd bit off
Text7 = Hex(outport_value)
out2_flag = 0
End If
End Sub

Private Sub Command7_Click()
If out1_flag = 0 And pwr_flag = 1 Then
Shape7.BackColor = &H80FF&
outport_value = outport_value Or &H2  '00000010 2nd bit on
Text7 = Hex(outport_value)
out1_flag = 1
Else
Shape7.BackColor = &HE0E0E0
outport_value = outport_value And &HFD '11111101 2nd bit off
Text7 = Hex(outport_value)
out1_flag = 0
End If
End Sub

Private Sub Command8_Click()
If out0_flag = 0 And pwr_flag = 1 Then
Shape8.BackColor = &H80FF&
outport_value = outport_value Or &H1  '00000001 1st bit on
Text7 = Hex(outport_value)
out0_flag = 1
Else
Shape8.BackColor = &HE0E0E0
outport_value = outport_value And &HFE '11111110 1st bit off
Text7 = Hex(outport_value)
out0_flag = 0
End If
End Sub

Private Sub Command9_Click()
If pwr_flag = 0 Then
Shape10.BackColor = &HFFFF&
pwr_flag = 1
Timer1.Enabled = True
Timer2.Enabled = True
Command9.Caption = "OFF"
Else
Shape10.BackColor = &H40C0&
pwr_flag = 0
Timer1.Enabled = False
Timer2.Enabled = False
Command9.Caption = "ON"
start_up
End If
End Sub

Private Sub Form_Load()
start_up
End Sub

Private Sub Form_Unload(Cancel As Integer)
Command12_Click
End Sub

Private Sub Timer1_Timer()
Dim busy_level
Out control_port, read_status
Text6 = Hex(Inp(input_port))
busy_level = Inp(input_port) And &H8
If busy_level = &H0 Then
edge_detect = edge_detect + 1
Shape9.BackColor = &HFF&
Else
Shape9.BackColor = &H800000
End If
If busy_level = &H8 And edge_detect > 10 Then
edge_detect = 0
Shape9.BackColor = &HFF&
Timer3.Enabled = True
Timer1.Enabled = False
End If
End Sub
Private Sub Timer2_Timer()
update_output
End Sub

Sub update_output()
Dim strobe_delay 'the strobe pulse latches the data to U6
strobe_delay = 10 'this sets pulse width approx
'update output port every 10mS
Out output_port, outport_value 'output the data to the output port
Out control_port, latch_out1 'latch the value to the IC U6 with IC U10B by strobing.
'150nS required put a 10uS delay here for a strobe pulse, works upto pentium 10GHz ?.
Do Until strobe_delay = 0
strobe_delay = strobe_delay - 1
Loop
Out control_port, &H0
End Sub

Sub start_up()
output_port = "&H378"
input_port = "&H379"
control_port = "&H37A"
Combo1.Text = "&H378"
Text1.Text = "0x" & Hex(output_port)
Text2.Text = "0x" & Hex(input_port)
Text3.Text = "0x" & Hex(control_port)
read_value = &HC
read_status = &H0
read_digits = &H8
outport_value = &H0 'set output port data going to U6 to 00000000
latch_out1 = &H3 ' 00000011 as AF and STB are inverted logic outputs.
out7_flag = out6_flag = out5_flag = out4_flag = out3_flag = out2_flag = out1_flag = out0_flag = 0
'the output port status of program set to 0 later in ini file if mem required.
pwr_flag = 0 ' turn off port activity till user turns on
Timer1.Enabled = False ' off outputs and inputs to ports
Timer2.Enabled = False ' off outputs and inputs to ports
Command1_Click
Command2_Click 'this i put as i could not fix a strange bug
Command3_Click ' or i just could not understand some concept
Command4_Click ' and then i do not have so much time
Command5_Click
Command6_Click 'this i put as i could not fix a strange bug
Command7_Click
Command8_Click
Shape1.BackColor = &HE0E0E0 ' turn off LEDs on GUI
Shape2.BackColor = &HE0E0E0
Shape3.BackColor = &HE0E0E0
Shape4.BackColor = &HE0E0E0
Shape5.BackColor = &HE0E0E0
Shape6.BackColor = &HE0E0E0
Shape7.BackColor = &HE0E0E0
Shape8.BackColor = &HE0E0E0
outport_value = &H0
update_output
edge_detect = 0
Shape9.BackColor = &H800000
digit_1 = 0
digit_2 = 0
digit_3 = 0
digit_4 = 0
digit_5 = 0
plus_minus = "+"
d1_dun = 0
d2_dun = 0
d3_dun = 0
d4_dun = 0
d5_dun = 0
dvm_reading = plus_minus & digit_5 & digit_4 & digit_3 & digit_2 & digit_1
End Sub

Private Sub Timer3_Timer()
Dim digit_code, digit_value
digit_value = 0
digit_code = 0
Out control_port, read_digits
digit_code = Inp(input_port) And &HF0 ' 0 lower nibble
digit_code = digit_code Xor &H80 ' invert 'ack' bit
digit_code = Str(Hex(digit_code)) ' hex as string
digit_code = digit_code * 0.1 'get rid of lower nibble
Text4 = digit_code
Out control_port, read_value
digit_value = Inp(input_port) And &HF0 ' 0 lower nibble
digit_value = digit_value Xor &H80 ' invert 'ack' bit
digit_value = Str(Hex(digit_value))
digit_value = digit_value * 0.1
Text5 = digit_value
Select Case digit_code
Case 1
digit_1 = digit_value
d1_dun = d1_dun + 1
Case 2
digit_2 = digit_value
d2_dun = d2_dun + 1
Case 4
digit_3 = digit_value
d3_dun = d3_dun + 1
Case 8
digit_4 = digit_value
d4_dun = d4_dun + 1
Case Else
End Select
get_d5
If (d1_dun > 2) And (d2_dun > 2) And (d3_dun > 2) And (d4_dun > 2) And (d5_dun > 1) Then
d5_pol
dvm_reading = plus_minus & digit_5 & digit_4 & digit_3 & digit_2 & digit_1
Timer1.Enabled = True
Timer3.Enabled = False
d1_dun = 0
d2_dun = 0
d3_dun = 0
d4_dun = 0
d5_dun = 0
End If
End Sub
Sub d5_pol()
Dim pol_fl
pol_fl = 0
Out control_port, read_status
pol_fl = Inp(input_port) And &H20 ' 0 lower nibble
pol_fl = Str(Hex(pol_fl))
pol_fl = pol_fl * 0.1
If pol_fl = 2 Then
plus_minus = "+"
Else: plus_minus = "- "
End If
End Sub
Sub get_d5()
Dim d5_fl, dgt_val
d5_fl = 0
dgt_val = 0
Out control_port, read_status
d5_fl = Inp(input_port) And &H10 ' 0 lower nibble
d5_fl = Str(Hex(d5_fl))
d5_fl = d5_fl * 0.1
If d5_fl = 1 Then
d5_dun = d5_dun + 1
Out control_port, read_value
dgt_val = Inp(input_port) And &HF0 ' 0 lower nibble
dgt_val = dgt_val Xor &H80 ' invert 'ack' bit
dgt_val = Str(Hex(dgt_val))
dgt_val = dgt_val * 0.1
digit_5 = dgt_val
End If
End Sub
